package com.wangp.mywrite.s_juc.concurrtent_tools;

import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.C;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author tooStronger
 * @date 2023/5/16
 */
@Slf4j
public class CyclicBarrierTest {

    private static final CyclicBarrier BARRIER = new CyclicBarrier(3,()-> log.info("子任务结束了"));


    public static void main(String[] args) throws BrokenBarrierException, InterruptedException {
        for (int i = 0; i < 3; i++) {
            new Thread(()->{
                log.info("开始执行");
                try {
                    Thread.sleep(500);
                    BARRIER.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
